package cn.yb.contorller;

import cn.yb.pojo.Xianli;
import cn.yb.servlet.xianliservlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.text.ParseException;
import java.util.List;

@Controller
public class xianlicontor {

    @Autowired
    public xianliservlet xianliservlet;

    @RequestMapping("/all")
    public String getDataAll(Model model){
        model.addAttribute("slist",xianliservlet.selectByAll());
        return "info";
    }

    @RequestMapping("/togo")
    public String toGoAdd(){
        return  "add";
    }

    @RequestMapping("/add")
    public String addxianli(@RequestParam("name")String name,@RequestParam("pass")String pass,@RequestParam("emila")String emila) throws ParseException {
        Xianli xianli = new Xianli();
        xianli.setName(name);
        xianli.setPass(pass);
        xianli.setEmila(emila);
        if(xianliservlet.addxianliser(xianli)>0){
            return  "redirect:all";
        }else{
        return "add";
        }
    }
}
